package aduros.display {

import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;

/** Various scene graph related helpers. */
public class DisplayUtil
{
    /** Removes all children from a DisplayObjectContainer. */
    public static function removeAllChildren (parent :DisplayObjectContainer) :void
    {
        while (parent.numChildren > 0) {
            parent.removeChildAt(0);
        }
    }

    /**
     * Ensure a DisplayObject is or is not a child of a container. You can also just toggle
     * the child's visibility, but this actually modifies the scene graph.
     */
    public static function setContains (
        parent :DisplayObjectContainer, child :DisplayObject, add :Boolean) :void
    {
        if (parent.contains(child) != add) {
            if (add) {
                parent.addChild(child);
            } else {
                parent.removeChild(child);
            }
        }
    }
}

}
